﻿$(document).ready(function(){
	
	//输入框提示
	$(".js_focusSelector").live('focus',function(){
		$(this).select();
		var inputIndex = $(".js_focusSelector").index(this);
		$('.js_inputTips').eq(inputIndex).fadeTo('fast',0.4);
		$(this).keyup(function(){
			if(this.value != ''){
				$('.js_inputTips').eq(inputIndex).hide();
			}
		})
		$(this).live('blur',function(){
			if(this.value == ''){
				$('.js_inputTips').eq(inputIndex).fadeTo('fast',1);
			}
		})
	});
	
	//更多登录方式
	var bodyHeight = $('body').height();
	var windowHeight = $(window).height();
	if(bodyHeight < windowHeight){$('body').height(windowHeight);}
	$('.choose_login').toggle(function(){
		$('.login_another').slideDown();
	},function(){
		$('.login_another').slideUp();
	})
	
	//评论框
	$('.co_in').focus(function(){
		$(this).animate({'height':60},'fast');
	})
	$('.co_in').blur(function(){
		var comm_text = $(this).val();
		if(comm_text == ''){
			$(this).animate({'height':25},'fast');
		}
	})
	
	//个人菜单
	$('.user_in').live('mouseenter',function(){
			$('.us_in').show();
		})
	$('.user_in').live('mouseleave',function(){
			$('.us_in').hide();
		})	

	
	//标题样式
	var url = location.pathname;
	var hostfile = url.split("/");
	var file = hostfile[hostfile.length-1];
	if(file == "index.php"){$(".head_menu ul li").eq(0).addClass("nav_current");}
	if(file == "new.php"){$(".head_menu ul li").eq(1).addClass("nav_current");}
	if(file == "hot.php"){$(".head_menu ul li").eq(2).addClass("nav_current");}
	if(file == "post_temp.php"){$(".head_menu ul li").eq(3).addClass("nav_current");}
	
	$(".login_in").live('click',function(){
		showLogin($(top.document));
		return false;
	});
	
});

//半透明层
var opacity = '<div class="opacity"></div>';

//登录弹出框
var login_html = '<div class="pa_login"><div class="close" title="关闭"><img src="/img/cancel.png"></div><form name="myform" method="POST">';
login_html += '<div class="lo_in pr"><span class="input_ico dib fl"></span><input class="mail_pw fl dib js_focusSelector" type="text" name="user_name" id="user_name"/><label class="js_inputTips pa" for="user_name">邮箱</label></div>';
login_html += '<div class="lo_in pr"><span class="input_ico dib fl" style=""></span><input class="mail_pw fl dib js_focusSelector" type="password" type="password" name="user_pwd" id="user_pwd"/><label class="js_inputTips pa" for="user_pwd">密码</label></div>';
login_html += '<div class="login_button">';
login_html += '<a href="#" onclick="return check_login();" class="lo_re_bo dib">登&nbsp&nbsp&nbsp&nbsp&nbsp录</a></div>';
login_html += '<div id="suggest" style="color:red"></div></form>';
login_html += '<div class="login_help"><a href="" class="f12 for">忘记密码？</a> &nbsp&nbsp<a href="register.php" class="f12 for">免费注册</a></div>	</div> ';

//显示登录弹出框
function showLogin(obj){
	obj.find("body").append(opacity).append(login_html);
	obj.find(".opacity").css({"width":$(top.window).width()+100+"px","height":$(top.window.document).height()+100+"px","position":"fixed","background-color":"#ccc","opacity":".8","left":"0px","top":"0px","z-index":"999"});
	obj.find(".pa_login").css({"z-index":"1000","position":"absolute","background-color":"#ffffff","opacity":".9","left":$(top.window).width()/2-150+"px",height:"200px",top:$(top.window).scrollTop()-250+"px"});
	obj.find(".pa_login").animate({top:$(top.window).scrollTop()+"px"},300,function(){
		$("#user_name").focus();
	});
	obj.find("body").css("overflow","hidden");
}

//登录检测
function check_login(){
	if($("#user_name").val()==''){G("suggest").innerHTML="请输入用户名";return false;}
	if($("#user_pwd").val()==''){G("suggest").innerHTML="请输入密码";return false;}
	var login = logins();
	if(login.length > 100){
		return false;
	}
	else if(login=='false'){G("suggest").innerHTML="用户名或密码错误";return false;}
	else if(login=='no user'){G("suggest").innerHTML="用户名不存在";return false;}
	return false;
}			

function G(id) {
  return document.getElementById(id);
}
		
function logins(){
	var temp
	$.ajax({url:"/ajax/user_login.php?request=1366&user_name="+$("#user_name").val()+"&user_pwd="+$("#user_pwd").val()+"",async:false,success:function(result){
		//alert(result);
		var strUrl=window.location.href;
		var arrUrl=strUrl.split("/");
		var strPage=arrUrl[arrUrl.length-1];
		$(".se_re").empty().html(result);
		$(".opacity").remove();
		$(".close:last").parent().remove();
		$(top.document).find("body").css("overflow","auto");
		if(strPage != "index.php"){
			message("登录成功");
		}
		$(".in_content").attr("src",$(".in_content").attr("src"));
		temp=result;
	}});
	return temp;
}
	
//关闭按钮
$(".close").live('click',function(){
	$(this).parent().remove();
	$(".opacity").remove();
	$(top.document).find("body").css("overflow","auto");
});

//渐隐消息功能
function message(info){
	var message = '<div class="liuzw_message" style="font-size:30px">'+info+'</div>';
	$(top.document).find("body").append(message);
	$(".liuzw_message").css({position:"absolute",top:$(top.window).scrollTop()+screen_height/2-20+"px",left:screen_width/2-40+"px","background-color":"#ccc",padding:"5px","font-weight":"blod"});
	setTimeout(function(){
		$(".liuzw_message").fadeTo(300,0,function(){
			$(".liuzw_message").remove();
		})
	},1000);
}

function getParam(paramName){
	paramValue = "";
	isFound = false;
	if (this.location.search.indexOf("?") == 0 && this.location.search.indexOf("=")>1){
	    arrSource = unescape(this.location.search).substring(1,this.location.search.length).split("&");
	    i = 0;
	    while (i < arrSource.length && !isFound){
	        if (arrSource[i].indexOf("=") > 0){
	             if (arrSource[i].split("=")[0].toLowerCase()==paramName.toLowerCase()){
	                paramValue = arrSource[i].split("=")[1];
	                isFound = true;
	             }
	        }
	        i++;
	    }   
	}
	return paramValue;
}